//
//  MYGHealthApi.swift
//  MYGrow
//
//  Created by 林矗 on 2024/4/5.
//

import Foundation
import Moya

enum MYGHealthApi {
    case bloodPressureList(startDate: String? = nil, endDate: String? = nil, page: Int? = nil, pageSize: Int? = nil, patientId: String)
    case heartRateList(startDate: String? = nil, endDate: String? = nil, page: Int? = nil, pageSize: Int? = nil, patientId: String)
    case bmiList(startDate: String? = nil, endDate: String? = nil, page: Int? = nil, pageSize: Int? = nil, patientId: String)
    case sugarList(startDate: String? = nil, endDate: String? = nil, page: Int? = nil, pageSize: Int? = nil, patientId: String)
    case reportList(patientId: String)
    case userInfo(patientId: String)
}

extension MYGHealthApi: MYGTargetType {
    var params: [String : Any] {
        var params: [String: Any] = [:]
        switch self {
        case .bloodPressureList(let startDate, let endDate, let page, let pageSize, let patientId),
                .heartRateList(let startDate, let endDate, let page, let pageSize, let patientId),
                .bmiList(let startDate, let endDate, let page, let pageSize, let patientId),
                .sugarList(let startDate, let endDate, let page, let pageSize, let patientId):
            if let startDate = startDate {
                params["start_at"] = startDate
            }
            
            if let endDate = endDate {
                params["end_at"] = endDate
            }
            
            if let page = page {
                params["page"] = page
            }
            
            if let pageSize = pageSize {
                params["pageSize"] = pageSize
            }
            params["patient_id"] = patientId
        case .userInfo(let patientId):
            params["id"] = patientId
        case .reportList(let patientId):
            params["patient_id"] = patientId
        default: break
        }
        return params
    }
    
    var path: String {
        switch self {
        case .bloodPressureList:
            "/api/health/blood_pressure"
        case .heartRateList:
            "/api/health/heart_rates"
        case .bmiList:
            "/api/health/weight"
        case .sugarList:
            "/api/health/blood_sugar"
        case .reportList:
            "/api/patient/get_medical_report_list"
        case .userInfo:
            "/api/patient/details"
        }
    }
    
    
    var method: Moya.Method {
        switch self {
        case .bloodPressureList, .heartRateList, .bmiList, .sugarList, .userInfo:
                .get
        case .reportList:
                .post
        }
    }
    
    var isServer: Int {
        1
    }
}
